﻿using System.Collections.Generic;

namespace FlyWeight
{
    class BigCharFactory
    {
        private Dictionary<string, BigChar> pool = new Dictionary<string, BigChar>();
        private static BigCharFactory singleton = new BigCharFactory();

        private BigCharFactory()
        {
        }

        public static BigCharFactory GetInstance()
        {
            return singleton;
        }

        public BigChar GetBigChar(char charName)
        {
            lock (this)
            {
                BigChar bc = null;

                if (pool.ContainsKey(charName.ToString()))
                {
                    bc = pool[charName.ToString()];
                }
                else
                {
                    bc = new BigChar(charName);
                    pool.Add(charName.ToString(), bc);
                }

                return bc;
            }
        }
    }
}
